// TypeScript file
class startView extends egret.DisplayObjectContainer {
    public constructor() {
        super();
        this.width = 750;
        this.height = 1334;
        this.init();
    }

    private image: egret.Bitmap;
    private shp: egret.Shape;

    private init() {
        this.initButton("遮罩移动", 20, 1000, this.move1);
        this.initshp();
        this.initImage();
    }

    private move1() {
        egret.Tween.get(this.shp).to({ x: 300 }, 2000, egret.Ease.sineIn).call(()=>{
            this.move2();
        });
    }

    private move2() {
        egret.Tween.get(this.shp).to({ y: 300 }, 2000, egret.Ease.sineIn).call(()=>{
            this.move3();
        });
    }

    private move3() {
        egret.Tween.get(this.shp).to({ x: 0 }, 2000, egret.Ease.sineIn).call(()=>{
            this.move4();
        });
    }

    private move4() {
        egret.Tween.get(this.shp).to({ y: 0 }, 2000, egret.Ease.sineIn).call(()=>{
            console.log("完成！！");
        });
    }

    //测试
    private test() {
        console.log("测试")
    }

    //初始化
    private initshp() {
        if (this.shp) {
            this.removeChild(this.shp);
            this.shp = null;
        }
        this.shp = new egret.Shape();
        this.shp.graphics.beginFill(0xff0000, 1);
        this.shp.graphics.drawRect(0, 0, 100, 100);
        this.shp.graphics.endFill();
        this.addChild(this.shp);
    }

    //初始化图片
    private initImage() {
        if (this.image) {
            this.removeChild(this.image);
            this.image = null;
        }
        this.image = new egret.Bitmap;
        this.image.texture = RES.getRes("1_jpg");
        this.image.mask = this.shp;
        this.addChild(this.image);
    }

    //通用按钮
    private initButton(textContent, x, y, callback) {
        var text: egret.TextField = new egret.TextField();
        text.text = textContent;
        text.textColor = 0x000000;
        text.background = true;
        text.backgroundColor = 0x03f425;
        text.x = x;
        text.y = y;
        text.touchEnabled = true;
        text.addEventListener(egret.TouchEvent.TOUCH_TAP, callback, this);
        this.addChild(text);
    }

}